$(document).ready(function(){
	$('body').keydown(function(event) {
		//Right
		if(event.keyCode == 39){
			camera.rotateY(10);
		//Left
		}else if(event.keyCode == 37){
			camera.rotateY(-10);
		//Up
		}else if(event.keyCode == 38){
			camera.rotateX(10);
		//Down
		}else if(event.keyCode == 40){
			camera.rotateX(-10);
		}
	});
	$('.cameraControl').change(function(event) {
		camera.position[0] = $("input[name=cameraPositionX]").val();
		camera.position[1] = $("input[name=cameraPositionY]").val();
		camera.position[2] = $("input[name=cameraPositionZ]").val();
		camera.rotate[0] = $("input[name=cameraRotateX]").val();
		camera.rotate[1] = $("input[name=cameraRotateY]").val();
		camera.rotate[2] = $("input[name=cameraRotateZ]").val();
		
	});
});

function Camera(){
	this.position = [0,0,7];
	this.rotate = [0,0,0];
}

Camera.prototype.refresh = function(){
	$("input[name=cameraPositionX]").val(this.position[0]);
	$("input[name=cameraPositionY]").val(this.position[1]);
	$("input[name=cameraPositionZ]").val(this.position[2]);
	$("input[name=cameraRotateX]").val(this.rotate[0]);
	$("input[name=cameraRotateY]").val(this.rotate[1]);
	$("input[name=cameraRotateZ]").val(this.rotate[2]);
};

Camera.prototype.rotateX = function(value){
	this.rotate[X] = parseInt(this.rotate[X] + value);
	this.refresh();
};

Camera.prototype.rotateY = function(value){
	this.rotate[Y] = parseInt(this.rotate[Y] + value);
	this.refresh();
};

Camera.prototype.rotateZ = function(value){
	this.rotate[Z] = parseInt(this.rotate[Z] + value);
	this.refresh();
};

Camera.prototype.positionX = function(value){
	this.position[X] = parseInt(this.position[X] + value);
	this.refresh();
};

Camera.prototype.positionY = function(value){
	this.position[Y] = parseInt(this.position[Y] + value);
	this.refresh();
};

Camera.prototype.positionZ = function(value){
	this.position[Z] = parseInt(this.position[Z] + value);
	this.refresh();
};
